//Shape.cpp

#include "Shape.h"

void Shape::setShifts(float shiftVer, float shiftHor)
{
	m_shiftVer = shiftVer;
	m_shiftHor = shiftHor;
}

void Shape::set(Point point, float shiftVer, float shiftHor)
{
	m_point = point;
	m_shiftVer = shiftVer;
	m_shiftHor = shiftHor;
}

void Shape::reloadOriginalShifts()
{
	m_shiftVer = m_originalShiftVer;
	m_shiftHor = m_originalShiftHor;
}

void Shape::saveShiftsToOriginal()
{
	m_originalShiftVer = m_shiftVer;
	m_originalShiftHor = m_shiftHor;
}

void Shape::execShiftsHor()
{
	int incX = 0;	//for inc/dec 1 from x in the rect point

	addBucketShiftHor();
	if (m_bucketHor >= 1)
	{
		if (getShiftHor() > 0)
		{
			incX = 1;
			m_bucketHor -= 1;
		}
		else
			if (getShiftHor() < 0)
			{
				incX = -1;
				m_bucketHor /*was +=*/-= 1;
			}
	}
	move(incX, 0);
}

void Shape::execShiftsVer()
{
	int incY = 0;	//for inc/dec 1 from Y in the rect point

	addBucketShiftVer();
	if (m_bucketVer >= 1)
	{
		if (getShiftVer() > 0)
		{
			incY = 1;
			m_bucketVer -= 1;
		}
		else
			if (getShiftVer() < 0)
			{
				incY = -1;
				m_bucketVer /*was +=*/-= 1;
			}
	}
	move(0, incY);
}

void Shape::execShifts()
{
	int incX = 0;	//for inc/dec 1 from x in the rect point
	int incY = 0;	//for inc/dec 1 from Y in the rect point

	//inc or dec the bucket acording the shift sign for the vertical shifts
	if (getShiftVer() > 0)
	{
		addBucketShiftVer();
	}
	else if (getShiftVer() < 0)
	{
		subBucketShiftVer();
	}
	//if the |vertical bucket| >= 1 inc/dex the y value and tkae cae the bucket
	if (abs(m_bucketVer) >= 1)
	{
		if (getShiftVer() > 0)
		{
			incY = 1;
			m_bucketVer -= 1;
		}
		else
			if (getShiftVer() < 0)
			{
				incY = -1;
				m_bucketVer += 1;
			}
	}
	//inc or dec the bucket acording the shift sign for the horizontal shifts
	if (getShiftHor() > 0)
	{
		addBucketShiftHor();
	}
	else if (getShiftHor() < 0)
	{
		subBucketShiftHor();
	}
	//if the |horizontal bucket| >= 1 inc/dex the x value and tkae cae the bucket
	if (abs(m_bucketHor) >= 1)
	{
		if (getShiftHor() > 0)
		{
			incX = 1;
			m_bucketHor -= 1;
		}
		else
			if (getShiftHor() < 0)
			{
				incX = -1;
				m_bucketHor += 1;
			}
	}
	move(incX, incY);
}
